package com.chenqq.adapter;

import com.chenqq.ChildFragment;

import java.util.ArrayList;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.Lifecycle;
import androidx.viewpager2.adapter.FragmentStateAdapter;

public class NewReportireAdapyer extends FragmentStateAdapter {
    private ArrayList<Fragment> fragments = new ArrayList<>();

    public NewReportireAdapyer(@NonNull FragmentActivity fragmentActivity) {
        super(fragmentActivity);
    }

    public NewReportireAdapyer(@NonNull Fragment fragment) {
        super(fragment);
    }

    public NewReportireAdapyer(@NonNull FragmentManager fragmentManager, @NonNull Lifecycle lifecycle) {
        super(fragmentManager, lifecycle);
    }

    public void setArrayList(ArrayList<ChildFragment> arrayList) {
        fragments.clear();
        fragments.addAll(arrayList);
        notifyDataSetChanged();
    }


    public void clearFragment() {
        for (Fragment fragment : fragments) {
            fragment.onDestroy();
        }
        fragments.clear();
    }

    @NonNull
    @Override
    public Fragment createFragment(int position) {
        return fragments.get(position);
    }

    public Fragment getPositionFragment(int position) {
        return fragments.get(position);
    }

    @Override
    public int getItemCount() {
        return fragments.size();
    }


}
